<?php
/**
 * Created by PhpStorm.
 * User: aaa
 * Date: 2017/4/18
 * Time: 9:44
 */


function base64ToImage($base,$name=null,$path = null)
{
    //提取base64编码出来
    $url = explode(',', $base);
    $day = date('Y-m-d', time());
    $rand = time() . mt_rand(11110, 99999999);
    $path = $path ? $path : './Public/Uploads/images/' . $day . '/';
    if (!is_dir($path)) {
        mkdir($path, 0777, true);
    }
    $name = $name ? $name : $rand . '.jpg';
    //return $path.$name;
    $size = file_put_contents($path . $name, base64_decode($url[1]));//返回的是字节数
    if ($size) {
        $path = $path . $name;
        return substr($path, 1);
    } else {
        return 0;
    }
}

    function get_service_type_name($id){
        $name=M('service_type')->where(array('id'=>$id))->getField('name');
        return $name;
    }

    function get_news_type_name($id){
        $name=M('news_type')->where(array('id'=>$id))->getField('name');
        return $name;
    }

    function get_scene_type_name($id){
        $name=M('scene_type')->where(array('id'=>$id))->getField('name');
        return $name;
    }

    function get_difficulty_type_name($id){
        $name=M('difficulty_type')->where(array('id'=>$id))->getField('name');
        return $name;
    }


    /**
     * 获取网站路劲的域名部分
     * @example https://www.baidu.com
     * @return string 返回域名
     */
    function get_webpath(){
        if($_SERVER['HTTPS'])
            $scheme = 'https://';
        else
            $scheme = 'http://';
        $webpath = $scheme.$_SERVER['HTTP_HOST'];
        return $webpath;
    }







